﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OAuth.Verifiers
{
    internal static class ServiceProviderVerifier
    {
        /// <summary>
        /// 
        /// </summary>
        /// <remarks>
        /// For guidelines regarding the creation of new exception types, see
        ///    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconerrorraisinghandlingguidelines.asp
        /// and
        ///    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp07192001.asp    
        /// </remarks>
        [global::System.Serializable]
        public class BadServiceProviderException : Exception
        {
            #region public BadServiceProviderException()

            /// <summary>
            /// Initializes a new instance of the <see cref="T:BadServiceProviderException"/> class
            /// </summary>
            public BadServiceProviderException()
            {
            }

            #endregion

            #region public BadServiceProviderException(string message) : base(message)

            /// <summary>
            /// Initializes a new instance of the <see cref="T:BadServiceProviderException"/> class
            /// </summary>
            /// <param name="message">A <see cref="T:System.String"/> that describes the error. The content of message is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture.</param>
            public BadServiceProviderException(string message)
                : base(message)
            {
            }

            public BadServiceProviderException(string message, Exception inner)
                : base(message, inner)
            {
            }


            #endregion

        }

        public static void VerifyServiceProvider(IServiceProvider pProvider)
        {
            if (pProvider == null)
                throw new BadServiceProviderException("Provider object may not be null");

            ServiceProviderUriVerifier.VerifyAccessTokenUri(new Uri(pProvider.AccessTokenRequest.Address));
            ServiceProviderUriVerifier.VerifyRequestTokenUri(new Uri(pProvider.RequestTokenRequest.Address));
        }
    }
}
